package com.lenovo.spider.component.parser;

import com.lenovo.spider.common.spi.ServiceProvider;
import com.lenovo.spider.component.TaskProcess.PageParser;
import com.lenovo.spider.domain.ResultItem;
import com.lenovo.spider.domain.Task;
import lombok.val;

/**
 * @author <a href="mailto:liuhan3@lenovo.com">HanL(liuhan3)</a>
 * on 2018/4/13 16:01
 */
@ServiceProvider
public class SimplePageParser implements PageParser {

    @Override
    public boolean support(Task task) {
        return task.isSuccess();
    }

    @Override
    public Task handle(Task task) {
        val response = task.getResponse();
        ResultItem item = new ResultItem(task.getCurUrl());

        item.addItem("title", response.getHtml().selectFirst("title").text());
        return task.setItem(item);
    }
}
